package com.mine.ability.controllers;

import com.mine.ability.model.Employee;
import com.mine.ability.services.EmployService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @功能
 * @创建时间 2020/4/13
 */
@RestController
@RequestMapping("/ablivity" )
@RefreshScope
public class AbilityController {
    @Autowired
    EmployService employService;

    @Value("${server.port}")
    private String port;
    @Value("${name}")
    private String name;

    @Value("${spring.cloud.client.ip-address}") //spring cloud 自动的获取当前应用的ip地址
    private String ip;

    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public Employee find(@PathVariable Integer id){
        Employee employee = employService.findById(id);
        employee.setAddress(port+":"+ip+name);
        return employee;

    }
    @RequestMapping(value = "/test")
    public String test() {
        return name;
    }
}
